示例#1
0
/*
 * Encode an "open type field".
 * #10.1, #10.2
 */
int
uper_open_type_put(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) {
	void *buf;
	void *bptr;
	ssize_t size;
	size_t toGo;

	ASN_DEBUG("Open type put %s ...", td->name);

	size = uper_encode_to_new_buffer(td, constraints, sptr, &buf);
	if(size <= 0) return -1;

	for(bptr = buf, toGo = size; toGo;) {
		ssize_t maySave = uper_put_length(po, toGo);
		ASN_DEBUG("Prepending length %d to %s and allowing to save %d",
			(int)size, td->name, (int)maySave);
		if(maySave < 0) break;
		if(per_put_many_bits(po, bptr, maySave * 8)) break;
		bptr = (char *)bptr + maySave;
		toGo -= maySave;
	}

	FREEMEM(buf);
	if(toGo) return -1;

	ASN_DEBUG("Open type put %s of length %ld + overhead (1byte?)",
		td->name, (long)size);

	return 0;
}
示例#2
0
/*
 * Encode an "open type field".
 * #10.1, #10.2
 */
int
uper_open_type_put(const asn_TYPE_descriptor_t *td,
                   const asn_per_constraints_t *constraints, const void *sptr,
                   asn_per_outp_t *po) {
    void *buf;
    void *bptr;
    ssize_t size;

    ASN_DEBUG("Open type put %s ...", td->name);

    size = uper_encode_to_new_buffer(td, constraints, sptr, &buf);
    if(size <= 0) return -1;

    ASN_DEBUG("Open type put %s of length %" ASN_PRI_SSIZE " + overhead (1byte?)", td->name,
              size);

    bptr = buf;
    do {
        int need_eom = 0;
        ssize_t may_save = uper_put_length(po, size, &need_eom);
        ASN_DEBUG("Prepending length %" ASN_PRI_SSIZE
                  " to %s and allowing to save %" ASN_PRI_SSIZE,
                  size, td->name, may_save);
        if(may_save < 0) break;
        if(per_put_many_bits(po, bptr, may_save * 8)) break;
        bptr = (char *)bptr + may_save;
        size -= may_save;
        if(need_eom && uper_put_length(po, 0, 0)) {
            FREEMEM(buf);
            return -1;
        }
    } while(size);

    FREEMEM(buf);
    if(size) return -1;

    return 0;
}