package bin

import 

const (
	// If L <= 253, the serialization contains one byte with the value of L,
	// then L bytes of the string followed by 0 to 3 characters containing 0,
	// such that the overall length of the value be divisible by 4,
	// whereupon all of this is interpreted as a sequence of int(L/4)+1 32-bit numbers.
	maxSmallStringLength = 253
	// If L >= 254, the serialization contains byte 254, followed by 3 bytes with
	// the string length L, followed by L bytes of the string, further followed
	// by 0 to 3 null padding bytes.
	firstLongStringByte = 254
)

func ( []byte,  string) []byte {
	 := len()
	if  <= maxSmallStringLength {
		 = append(, byte())
		 = append(, ...)
		 :=  + 1
		 = append(, make([]byte, nearestPaddedValueLength()-)...)
		return 
	}

	 = append(, firstLongStringByte, byte(), byte(>>8), byte(>>16))
	 = append(, ...)
	 :=  + 4
	 = append(, make([]byte, nearestPaddedValueLength()-)...)

	return 
}

func ( []byte) ( int,  string,  error) {
	if len() == 0 {
		return 0, "", io.ErrUnexpectedEOF
	}
	if [0] == firstLongStringByte {
		if len() < 4 {
			return 0, "", io.ErrUnexpectedEOF
		}
		 := uint32([1]) | uint32([2])<<8 | uint32([3])<<16
		if len() < (int() + 4) {
			return 0, "", io.ErrUnexpectedEOF
		}
		return nearestPaddedValueLength(int() + 4), string([4 : +4]), nil
	}
	 := int([0])
	if len() < ( + 1) {
		return 0, "", io.ErrUnexpectedEOF
	}
	if  > maxSmallStringLength {
		return 0, "", &InvalidLengthError{
			Length: ,
			Where:  "string",
		}
	}
	return nearestPaddedValueLength( + 1), string([1 : +1]), nil
}