BitEncoderChannel.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2007-2012 Siemens AG
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published
  6. * by the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*******************************************************************
  19. *
  20. * @author Daniel.Peintner.EXT@siemens.com
  21. * @version 0.6
  22. * @contact Joerg.Heuer@siemens.com
  23. *
  24. * <p>Code generated by EXIdizer</p>
  25. ********************************************************************/
  26. #include "EncoderChannel.h"
  27. #include "CoderChannel.h"
  28. #include "BitOutputStream.h"
  29. #include "EXITypes.h"
  30. #ifndef BIT_ENCODER_CHANNEL_C
  31. #define BIT_ENCODER_CHANNEL_C
  32. #if EXI_ALIGNMENT == BIT_PACKED
  33. int encode(bitstream_t* stream, uint8_t b) {
  34. return writeBits(stream, 8, b);
  35. }
  36. /**
  37. * Encode a single boolean value. A false value is encoded as bit 0 and true
  38. * value is encode as bit 1.
  39. */
  40. int encodeBoolean(bitstream_t* stream, int b) {
  41. uint8_t val = b ? 1 : 0;
  42. return writeBits(stream, 1, val);
  43. }
  44. /**
  45. * Encode n-bit unsigned integer. The n least significant bits of parameter
  46. * b starting with the most significant, i.e. from left to right.
  47. */
  48. int encodeNBitUnsignedInteger(bitstream_t* stream, uint16_t nbits, uint32_t val) {
  49. if (nbits > 0) {
  50. return writeBits(stream, nbits, val);
  51. }
  52. return 0;
  53. }
  54. /**
  55. * Flush underlying bit output stream.
  56. */
  57. int encodeFinish(bitstream_t* stream) {
  58. return flush(stream);
  59. }
  60. #endif /* alignment */
  61. #endif