writeExtensionFormatHeader method

void writeExtensionFormatHeader(
  1. ExtensionHeader extensionHeader
)

Implementation

void writeExtensionFormatHeader(ExtensionHeader extensionHeader) {
  int dataLength = extensionHeader.length;
  int typeCode = extensionHeader.typeCode;
  switch (dataLength) {
    case 1:
      _bytesBuilder.add(<int>[MessagePackCode.fixExt1, typeCode]);
      return;
    case 2:
      _bytesBuilder.add(<int>[MessagePackCode.fixExt2, typeCode]);
      return;
    case 4:
      _bytesBuilder.add(<int>[MessagePackCode.fixExt4, typeCode]);
      return;
    case 8:
      _bytesBuilder.add(<int>[MessagePackCode.fixExt8, typeCode]);
      return;
    case 16:
      _bytesBuilder.add(<int>[MessagePackCode.fixExt16, typeCode]);
      return;
    default:
      if (dataLength <= _maxUint8) {
        _bytesBuilder.add(<int>[MessagePackCode.ext8, dataLength, typeCode]);
      } else if (dataLength <= _maxUint16) {
        _bytesBuilder.addByte(MessagePackCode.ext16);
        _writeBigEndianShort(dataLength);
        _bytesBuilder.addByte(typeCode);
      } else {
        _bytesBuilder.addByte(MessagePackCode.ext32);
        _writeBigEndianInt(dataLength);
        _bytesBuilder.addByte(typeCode);
      }

      break;
  }
}